﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BiocityFilmquizAdmin.Src.SessionHandle;
using BiocityFilmquizAdmin.Src.Domain;

namespace BiocityFilmquizAdmin
{
    public partial class masterpage : System.Web.UI.MasterPage
    {
        SessionController sessionController;

        protected void Page_Load(object sender, EventArgs e)
        {
            sessionController = new SessionController();

            notSucces.Visible = false;
        }

        private void Page_PreRender(object sender, System.EventArgs e)
        {
            if (Session["loggedIn"] != null && (bool)Session["loggedIn"])
            {
                notLoggedInDiv.Visible = false;
                loggedInDiv.Visible = true;
                usernameLabel.Text = ((User)Session["user"]).name;

            }
            else
            {
                loggedInDiv.Visible = false;
                notLoggedInDiv.Visible = true;
            }
        }

        protected void loginButton_Click(object sender, EventArgs e)
        {
            User user = sessionController.LoginAdminUser(usernameTxt.Text, passwordTxt.Text, Session);
            if (user == null)
            {
                notSucces.Visible = true;
            }
        }

        protected void logoutButton_Click(object sender, EventArgs e)
        {
            sessionController.logoutUser(Session);
        }
    }
}